/*
 * @(#)Facade.java
 *
 * Revision:
 * Author                                         Date           
 * --------------------------------------------   ------------   
 *  Jeremias D. Serafim de Araujo                     14/11/2012  
 *    
 */


package br.edu.ufcg.splab.util;




import java.io.FileNotFoundException;
import java.io.IOException;

import org.naturalcli.ExecutionException;
import org.naturalcli.InvalidSyntaxException;

import br.edu.ufcg.splab.core.InterfaceGenerate;
import br.edu.ufcg.splab.core.InterfaceGraph;
import br.edu.ufcg.splab.core.graph.Tree;
import br.edu.ufcg.splab.exceptions.LTSBTException;
import br.edu.ufcg.splab.exceptions.ParseException;
import br.edu.ufcg.splab.generator.ConvertGraphToTree;
import br.edu.ufcg.splab.generator.TestSuite;
import br.edu.ufcg.splab.io.TestLinkXMLPreAndPostConditionWriter;
import br.edu.ufcg.splab.techniques.reduction.requirement.RequirementTracer;
import br.edu.ufcg.splab.techniques.reduction.requirement.TransitionPairsTracerGenerator;
import br.edu.ufcg.splab.techniques.reduction.strategies.ReductionSimilarity;
import br.edu.ufcg.splab.util.commands.CommandParser;


public class Facade {
	
	private static Controller control = new Controller();

	/**
	 * This function is responsible for generating of 
	 * cases of test, it  has 3 parameter of input
	 * {@link https://sites.google.com/a/computacao.ufcg.edu.br/lts-bt/home/algorithm}
	 * 
	 * @param String fileInputName is the name of model stated in tgf. ex: "modelo1.tgf"
	 * @param int numExpansion is integer that indicates how many times exercise the loop
	 * @param String fileOutputName is the name of file where saved test cases
	 * @throws LTSBTException 
	 * @throws FileNotFoundException 
	 * 
	 */
	public void generateFromTree(String fileInputName, int numExpansion,String fileOutputName) throws FileNotFoundException, LTSBTException{
	  // tirar esse syso
	   //System.out.println(control.generateFromTree(fileInputName, numExpansion, fileOutputName));

	   control.generateFromTree(fileInputName, numExpansion, fileOutputName);
	  
	}
	
	/**
	 * This function generates test cases
	 * 
	 * @param fileInputName is the name of tgf model
	 * @param fileOutputName is the name of file where saved test cases
	 * @throws LTSBTException 
	 * @throws FileNotFoundException 
	 *
	 */
	
	public void generateFromGraph(String fileInputName,String fileOutputName) throws FileNotFoundException, LTSBTException{
		//TestSuite testSuite = ;
		//System.out.println(control.generateFromGraph(fileInputName, fileOutputName));
		 control.generateFromGraph(fileInputName, fileOutputName);
	}
	
	/**
	 * This function is responsible for generating of 
	 * cases of test, it  has 3 parameter of input
	 * {@link https://sites.google.com/a/computacao.ufcg.edu.br/lts-bt/home/algorithm}
	 * 
	 * @param String fileInputName is the name of annotated model stated in tgf. ex: "modelo1.tgf"
	 * @param int numExpansion is integer that indicates how many times exercise the loop
	 * @param String fileOutputName is the name of file where saved test cases
	 * @throws LTSBTException 
	 * @throws FileNotFoundException 
	 * 
	 */
	public void generateAnnotatedGraphFromTree(String fileInputName, int numExpansion,String fileOutputName) throws FileNotFoundException, LTSBTException{
	  // tirar esse syso
	   //System.out.println(control.generateFromTree(fileInputName, numExpansion, fileOutputName));
		control.generateAnnotatedGraphFromTreeTestLink(fileInputName, numExpansion, fileOutputName);
	
	}

	/**
	 * This function generates test cases
	 * 
	 * @param fileInputName is the name of tgf annotated model
	 * @param fileOutputName is the name of file where saved test cases
	 * @throws LTSBTException 
	 * @throws FileNotFoundException 
	 *
	 */
	
	public void generateAnnotatedGraphFromGraph(String fileInputName,String fileOutputName) throws FileNotFoundException, LTSBTException{
		//TestSuite testSuite = ;
		//System.out.println(control.generateFromGraph(fileInputName, fileOutputName));
		 control.generateAnnotatedGraphFromGraphTestLink(fileInputName, fileOutputName);
	}
	/**
	 * Remove the paths with high similarity
	 * 
	 * @param testSuite is a list of cases of test
	 * @param percent is the percentage of the remaining list
	 * @param fileOutputName is the name of the output file where is the 
	 * percentage of test cases desired
	 * @throws IOException 
	 * @throws ParseException 
	 */
	
	
	public void similaridade(String testSuite,double percent,String fileOutputName) throws ParseException, IOException{		
		control.startSimilarity(testSuite, percent, fileOutputName);
		//control.startSimilarity(testSuite, percent);	
	}
	
	/**
	 * Reduces test suite using reduction algorithm based on similarity. 
	 * It uses as default the old LTS generation algorithm.
	 *  
	 * @param fileInputName The file (tgf) with a specification model (LTS model).
	 * @param fileOutputName The output filename. 
	 * @throws Exception
	 */
	public void reduceSimFromGraphToGraph(String fileInputName, String fileOutputName, String type) throws Exception{
		control.reduceSimFromGraphToGraph(fileInputName, fileOutputName, type);
	}
	
	/**
	 * Reduces test suite using reduction algorithm based on similarity. 
	 * It used as input an simple LTS. It uses parameterized LTS as generation algorithm.
	 *  
	 * @param fileInputName The file (tgf) with a specification model (LTS model).
	 * @param numOfExpansion The number of expansions in the tree for generation with loop coverage.
	 * @param fileOutputName The output filename.
	 * @throws Exception
	 */
	public void reduceSimFromGraphToTree(String fileInputName, int numOfExpansion, String fileOutputName, String type) throws Exception{
		control.reduceSimFromGraphToTree(fileInputName, numOfExpansion, fileOutputName, type);
	}
	
	/**
	 * Reduces test suite using reduction algorithm based on similarity. 
	 * It used as input an annotated graph. 
	 * It uses as default the old LTS generation algorithm.
	 * 
	 * @param fileInputName The file (tgf) with a specification model (LTS model).
	 * @param fileOutputName The output filename. 
	 * @throws Exception
	 */
	public void reduceSimFromAnnotatedGraphToGraph(String fileInputName, String fileOutputName, String type) throws Exception{
		control.reduceSimFromAnnotatedGraphToGraphTestLink(fileInputName, fileOutputName, type);
	}
	
	/**
	 * Reduces test suite using reduction algorithm based on similarity. 
	 * It used as input an annotated graph.
	 * It uses parameterized LTS as generation algorithm.
	 * 
	 * @param fileInputName The file (tgf) with a specification model (LTS model).
	 * @param numOfExpansion The number of expansions in the tree for generation with loop coverage.
	 * @param fileOutputName The output filename.
	 * @throws Exception
	 */
	public void reduceSimFromAnnotatedGraphToTree(String fileInputName, int numOfExpansion, String fileOutputName, String type) throws Exception{
		control.reduceSimFromAnnotatedGraphToTreeTestLink(fileInputName, numOfExpansion, fileOutputName, type);
	}
	
	/**
	 * Method responsible for call the method {@link br.edu.ufcg.splab.util.Controller#generateGraphs generateGraphs} of the class Controller to generate the set of graphs.
	 * 
	 * @param depth
	 *            The maximum depth of the generated LTS,in other words,the biggest level between the root and the final state.
	 * @param quantity
	 *            The number of generated LTSs.
	 * @param nLoops
	 *            Quantity of  {@link br.edu.ufcg.splab.simulator.StructuralPattern#loop loops} to be inserted in the LTSs.           
	 * @param nJoins
	 *            Quantity of  {@link br.edu.ufcg.splab.simulator.StructuralPattern#join joins} to be inserted in the LTSs.
	 * @param nForks
	 *            Quantity of  {@link br.edu.ufcg.splab.simulator.StructuralPattern#fork forks} to be inserted in the LTSs.
	 * @param directorio
	 * 			The path to put the files
	 * @throws IOException 
	 * @throws LTSBTException 
	 *			
	 */
	public String generateGraphs(int depth, int quantity, int nLoops,int nJoins, int nForks,String directorio) throws LTSBTException, IOException{
		String log = control.generateGraphs(depth, quantity, nLoops, nJoins, nForks, directorio);	
		return log;
	}
	
	public void selectSART(String baselineFile, String deltaFile, String outputFilename) throws Exception{
		control.selectSART(baselineFile, deltaFile, outputFilename);
	}

	//private static String[] commands = {"generate", "generate_annotated", "select"};
	//private static String[] generationTypes = {"DFS", "parameterizedDFS"};
	
	public static void main(String args[]){
		try {
			Facade facade = new Facade();
			CommandParser commandParser = new CommandParser(facade);
			commandParser.execute(args);
		} catch (InvalidSyntaxException e) {
			System.out.println(e.getMessage());
		} catch (ExecutionException e) {
			System.out.println(e.getMessage());
		}
	}
}